package com.yancy.service.impl;

import com.yancy.dao.NewDao;
import com.yancy.dao.impl.NewDaoImpl;
import com.yancy.entity.New;
import com.yancy.service.NewService;

import java.util.List;
import java.util.Random;
import java.util.UUID;

public class NewServiceImpl implements NewService {

    @Override
    public List<New> getNew() {
        NewDao newDao = new NewDaoImpl();
        return newDao.getNew();
    }

    @Override
    public boolean delete(String id) {
        NewDao newDao = new NewDaoImpl();
        return newDao.delete(id);
    }

    @Override
    public boolean update(New updateNew) {
        NewDao newDao = new NewDaoImpl();
        return newDao.update(updateNew);
    }

    @Override
    public boolean add(New addNew) {
        /*生成随机10位id*/
        String uuid = UUID.randomUUID().toString().replaceAll("-","").substring(0,10);
        addNew.setId(uuid);
        NewDao newDao = new NewDaoImpl();
        return newDao.add(addNew);
    }

    @Override
    public New getSingleNew(String id) {
        NewDao newDao = new NewDaoImpl();
        return newDao.getSingleNew(id);
    }

}
